/**
 * Load the library located at the same path with this file
 */
(function () {
  //定义要加载的js和css文件路径
  var url_list = {
    css: [
      '/third/element-plus/index.css', //elementUI样式
      '/third/vxe-table/lib/style.css', //vxe表格样式
      '/css/common.css', //vxe表格样式
    ],
    js: [
      '/third/vue/vue.js', //vue
      // "/third/qs/qs.min.js",//axios序列化参数第三方包
      '/third/axios/axios.min.js', //axios请求包
      '/third/element-plus/index.js', //elementUI框架js
      '/third/element-plus/icons.js',//element-Icon框架js
      '/third/vxe-table/xe-utils.js', //vxe表格使用第三方工具
      '/third/vxe-table/vxe-table.js', //vxe表格
      '/third/echart/echarts.js' //echarts图表
    ],
  };

  var dynamicLoading = {
    css: function (path) {
      if (!path || path.length === 0) {
        throw new Error('argument "path" is required !');
      }
      var head = document.getElementsByTagName('head')[0];
      var link = document.createElement('link');
      link.href = path;
      link.rel = 'stylesheet';
      link.type = 'text/css';
      head.appendChild(link);
    },
    js: function (path) {
      if (!path || path.length === 0) {
        throw new Error('argument "path" is required !');
      }
      var head = document.getElementsByTagName('head')[0];
      var script = document.createElement('script');
      script.src = path;
      script.type = 'text/javascript';
      head.appendChild(script);
    },
  };

  var scripts = document.getElementsByTagName('script'),
    path,
    i,
    ln,
    scriptSrc,
    match;
  var script_current = null;
  for (i = 0, ln = scripts.length; i < ln; i++) {
    scriptSrc = scripts[i].src;

    match = scriptSrc.match(/collection\.js$/);
    if (match) {
      script_current = scripts[i];
      /**
       * use a path without the bootstrap.js file on it. http://path/to/ext/bootstrap.js will become
       * http://path/to/ext/
       */
      path = scriptSrc.substring(0, scriptSrc.length - match[0].length);
      break;
    }
  }

  if (url_list != null && url_list.css != null) {
    for (var i in url_list.css) {
      // document.write('<link href="' + url_list.css[i] + '" rel="stylesheet" />');
      dynamicLoading.css(url_list.css[i]);
    }
  }
  if (url_list != null && url_list.js != null) {
    for (var i in url_list.js) {
      // if (url_list.js[i].type) {
      //     document.write('<script type="text/babel" charset="UTF-8" src="' + url_list.js[i].js + '" ></script>');
      // } else {
      //     document.write('<script type="text/javascript" charset="UTF-8" src="' + url_list.js[i].js + '" ></script>');
      // }
      document.write(
        '<script type="text/javascript" charset="UTF-8" src="' + url_list.js[i] + '" ></script>',
      );
      // dynamicLoading.js(url_list.js[i])
    }
  }
  //定义eventBus公用方法
})();
